#include "Function.hpp"
#include "EquationSolver.hpp"
#include <iostream>
#include <cmath>

// Class for the function f(x) = x - tan(x)
class F5 : public Function {
public:
    double operator() (double x) const {
        return x - tan(x);  // f(x) = x - tan(x)
    }

    // Override the derivative function for Newton's method
    double derivative(double x) const {
        double u = 1/cos(x);
        return 1 - u * u;  // Derivative: f'(x) = 1 - sec^2(x)
    }
};

// Function to solve f(x) = x - tan(x) using Newton's Method with an initial guess x0
void solve_newton_method(double x0) {
    std::cout << "Solving x = tan(x) using Newton's method, starting from " << x0 << std::endl;
    Newton_Method solver(F5(), x0);  // Initialize Newton's method solver with F5
    double x = solver.solve();  // Solve for the root
    std::cout << "An approximate root near " << x0 << " is: " << x << std::endl;
}

int main() {
    solve_newton_method(4.5);  // Find the root near 4.5
    solve_newton_method(7.7);  // Find the root near 7.7

    return 0;
}
